package ${package};

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;
import ${project.attrs.basePackage}.model.${it.name.className};
import ${project.attrs.basePackage}.service.${it.name.className}Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * ${it.name} - ${it.comment}
 *
 * @author ${SYS['user.name']}
 */
@RestController
@RequestMapping("${it.name.fieldName.s}")
public class ${it.name.className}Controller {

    @Resource
    private ${it.name.className}Service ${it.name.fieldName}Service;

    @PostMapping(value = "/save")
    public DataResponse<${it.name.className}> save(@RequestBody ${it.name.className} ${it.name.fieldName}) {
        return DataResponse.ok(${it.name.fieldName}Service.save(${it.name.fieldName}));
    }

    @PostMapping
    public RowsResponse<${it.name.className}> findList(@RequestBody ${it.name.className} ${it.name.fieldName}) {
        return RowsResponse.ok(${it.name.fieldName}Service.findList(${it.name.fieldName}));
    }

    @GetMapping
    public DataResponse<${it.name.className}> findById(@RequestParam("id") Long id) {
        return DataResponse.ok(${it.name.fieldName}Service.findById(id));
    }

    @PutMapping
    public DataResponse<${it.name.className}> update(@RequestParam("id") Long id, @RequestBody ${it.name.className} ${it.name.fieldName}) {
        ${it.name.fieldName}.setId(id);
        return DataResponse.ok(${it.name.fieldName}Service.update(${it.name.fieldName}));
    }

    @DeleteMapping
    public DataResponse<Boolean> deleteById(@RequestParam("id") Long id) {
        return DataResponse.ok(${it.name.fieldName}Service.deleteById(id) == 1);
    }

}